package com.itcast.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;

import com.itcast.dao.UserDao;
import com.itcast.domain.User;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao{
	
	  private JdbcTemplate jdbcTemplate;  
      
	    public JdbcTemplate getJdbcTemplate() {  
	        return jdbcTemplate;  
	    }  
	     
	    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {  
	        this.jdbcTemplate = jdbcTemplate;  
	    }  
	
	@Override
	public void save(User user) {
		this.getHibernateTemplate().save(user);
	}

	@Override
	public void update(User user) {
		this.getHibernateTemplate().update(user);
	}

	@Override
	public void delete(User user) {
		this.getHibernateTemplate().delete(user);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<User> findByAccount(String account) { 
		String hql = "from User where account = ?";
		return (List<User>) this.getHibernateTemplate().find(hql,account);
	}

	@Override
	public User findById(Integer id) {
		return this.getHibernateTemplate().get(User.class, id);
		
	}

	@Override
	public List<?> findAll() {
		return this.getHibernateTemplate().find("from User");
	}

	
	
	

}
